package com.zmn.oms.task.listener;

import com.alibaba.fastjson.JSON;
import com.zmn.biz.mds.common.dto.VoiceDetectionDTO;
import com.zmn.manager.mq.annotation.AliyunMQHandler;
import com.zmn.manager.mq.annotation.AliyunMQListener;
import com.zmn.oms.common.constant.MessageQueueTagConsts;
import com.zmn.oms.model.entity.orderworkingrecord.OrderWorkingRecord;
import com.zmn.oms.services.interfaces.orderworkingrecord.OrderWorkingRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 工程师上门录音语音质检监听
 *
 * @author chengguang
 * @date 2022/09/01
 */
@AliyunMQListener(topic = "${spring.mq.topic.oms}")
@Component
@Slf4j
public class OrderWorkingRecordListener {

    @Resource
    private OrderWorkingRecordService orderWorkingRecordService;

    @AliyunMQHandler(tags = MessageQueueTagConsts.WORKING_RECORD_QUALITY)
    public void updateDetectionResult(String message) {

        try {
            log.info("OrderWorkingRecordListener.updateDetectionResult 入参,{}",message);
            VoiceDetectionDTO voiceDetectionDTO = JSON.parseObject(message, VoiceDetectionDTO.class);
            OrderWorkingRecord orderWorkingRecord = new OrderWorkingRecord();
            orderWorkingRecord.setRecordId(Long.valueOf(voiceDetectionDTO.getBizRecordId()));
            orderWorkingRecord.setDetectionResult(voiceDetectionDTO.getDetectResult());
            orderWorkingRecordService.updateByKey(orderWorkingRecord);
        } catch (Exception e) {
            log.error("OrderWorkingRecordListener.updateDetectionResult 失败{}", e.getMessage(), e);
        }


    }

}
